﻿using System;
using System.Collections.Generic;

namespace AEM.Data.BLL.Actions
{
    public static class PeakSetting
    {
        static PeakSetting()
        {
            AddPeak = doAddPeak;
            ModifiyPeak = doModifiyPeak;
            DeletePeak = doDeletePeak;
            List = doList;
        }

        private static AddPeakResult doAddPeak(Model.PeakSetting value)
        {
            if (null == value) return AddPeakResult.IsNull;

            bool ret = DAL.PeakSetting.Add(value);
            if (ret)
                return AddPeakResult.OK;
            else
                return AddPeakResult.Error;
        }

        private static ModifiyPeakResult doModifiyPeak(Model.PeakSetting value)
        {
            if (null == value) return ModifiyPeakResult.IsNull;
            if (!DAL.PeakSetting.Exist(value.ID)) return ModifiyPeakResult.IsNotExist;
            bool ret = DAL.PeakSetting.Update(value);
            if (ret)
                return ModifiyPeakResult.OK;
            else
                return ModifiyPeakResult.Error;
        }

        private static DeletePeakResult doDeletePeak(int id)
        {
            if (!DAL.PeakSetting.Exist(id)) return DeletePeakResult.IsNotExist;

            bool ret = DAL.PeakSetting.Delete(id);
            if (ret)
                return DeletePeakResult.OK;
            else
                return DeletePeakResult.Error;
        }

        private static List<Model.PeakSetting> doList(string condition)
        {
            return DAL.PeakSetting.List(condition);
        }

        public static Func<Model.PeakSetting, AddPeakResult> AddPeak;
        public static Func<Model.PeakSetting, ModifiyPeakResult> ModifiyPeak;
        public static Func<int, DeletePeakResult> DeletePeak;
        public static Func<string, List<Model.PeakSetting>> List;

        public static Action Reload;

        public enum AddPeakResult
        {
            OK,
            IsNull,
            IsExist,
            Error
        }

        public enum ModifiyPeakResult
        {
            OK,
            IsNull,
            IsNotExist,
            Error
        }

        public enum DeletePeakResult
        {
            OK,
            IsNotExist,
            Error
        }
    }
}
